class Solution {
public:
    int totalFruit(vector<int>& fruits) {
        int hash[100010]={0},kinds=0,ans=0,sum=0;
        for(int left=0,right=0;right<fruits.size();++right)
        {
            if(hash[fruits[right]]++==0) ++kinds;
            while(left<right&&kinds>2)
            {
                --hash[fruits[left]];
                if(hash[fruits[left++]]==0) --kinds;
            }
            ans=max(ans,right-left+1);
        }
        return ans;
    }
};